package com.bxmdm.ragdemo.service;


import com.bxmdm.ragdemo.domain.EventBean;
import com.bxmdm.ragdemo.tool.DateTimeTools;
import java.util.Date;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AgentService {

	private final OpenAiChatModel chatModel;

	public String toolChat(String message) {
		return ChatClient.create(chatModel).prompt(message)
				.advisors(new SimpleLoggerAdvisor())
				.tools(new DateTimeTools())
				.call()
				.content();
	}


	record ActorsFilms(String eventTitle,
										 Date eventDate,
										 String eventLocation,
										 String eventOverview,
										 List<String> eventParticipantList) {}
	public List<EventBean> getNewsEventList(String message) {
		return ChatClient.create(chatModel).prompt()
				.user(u -> u.text("帮我提取以下新闻中的事件: {news}.\n 请以中文填充数据")
						.param("news", message))
				.advisors(new SimpleLoggerAdvisor())
				.call()
				.entity(new ParameterizedTypeReference<List<EventBean>>() {
				});
	}
}
